/*
 * BitSetSerializer_gtest.h
 *
 *  Created on: Nov 25, 2012
 *      Author: m
 */

#ifndef BITSETSERIALIZER_GTEST_H_
#define BITSETSERIALIZER_GTEST_H_

#include <gtest/gtest.h>
#include <memory>
#include "../physical_layer/serializers/BitSetSerializer.h"

using physical::BitSetSerializer;
using physical::byte;

/**
 * Test Suite de la clase BitSetSerializer
 */
class BitSetSerializerTestFixture : public ::testing::Test
{
public:
    BitSetSerializerTestFixture()
    {
    }

    virtual ~BitSetSerializerTestFixture()
    {
    }

    void SetUp()
    {
    }

    void TearDown()
    {
    }
};

/**
 * Test Add and retrieve one phrase in the dictionary
 *
 *
 */
TEST_F( BitSetSerializerTestFixture,  SerializeAndDeserializeABitSetOf128Bits)
{

    BitSetSerializer<128> serializer;

    // Creo un bitset que voy a serializar y deserializar
    std::bitset<128> bitset( std::string(
        "11001100"
        "11110000"
        "01001010"
        "00000001"
        "10000001"
        "01111110"
        "01010101"
        "10101010"
        "11111111"
        "00000000"
        "11001111"
        "00111100"
        "11000000"
        "11100111"
        "10000000"
        "10111000" ) );

    std::bitset<128> deserializedBitset;
    byte buffer[ 128/8 ];

    size_t expectedSerializationSize = serializer.getSize( bitset );
    size_t serializationSize   = serializer.serialize( bitset, buffer );
    size_t deserializationSize = serializer.deserialize( buffer, deserializedBitset );

    // Verifico que los tamaños sean iguales
    ASSERT_EQ( serializationSize, deserializationSize );
    ASSERT_EQ( expectedSerializationSize, serializationSize );

    //ASSERT_EQ( buffer, expectedSerialization );

    // Verifico que sean del valor correcto
    ASSERT_EQ( serializationSize, size_t(128/8) );

    ASSERT_EQ( bitset.to_string(), deserializedBitset.to_string() );

}

#endif /* BITSETSERIALIZER_GTEST_H_ */
